package com.wxyzz.canteenadmin.sys.service.impl;

import com.wxyzz.canteenadmin.sys.mapper.SysUserMapper;
import com.wxyzz.canteenadmin.sys.param.LoginParam;
import com.wxyzz.canteenadmin.sys.service.SysUserService;
import com.wxyzz.canteencommon.entity.sys.SysUser;
import com.wxyzz.canteencommon.exception.CustmerException;
import com.wxyzz.canteencommon.utils.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/10/6
 * @Solgne 从想做到能做
 * @Desc
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public SysUser login(LoginParam loginParam) {
        SysUser sysUser = sysUserMapper.selectSysUserByUsername(loginParam.getUsername());
        if (sysUser == null) {
            throw new CustmerException(500,"用户名不存在");
        }
//        if (!sysUser.getPassword().equals(loginParam.getPassword())) {
//            throw new CustmerException(500,"密码错误");
//        }
        if(!SecurityUtil.verify(loginParam.getPassword(),sysUser.getPassword())){
            throw new CustmerException(500,"密码错误");
        }
        return sysUser;
    }


}
